define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            $(".btn-edit").data("area",["1000px","600px"]);//顶部编辑按钮

            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'store/store/index' + location.search,
                    add_url: 'store/store/add',
                    edit_url: 'store/store/edit',
                    del_url: 'store/store/del',
                    multi_url: 'store/store/multi',
                    import_url: 'store/store/import',
                    table: 'store',
                }
            });

            var table = $("#table");
            var chuzhishow = false;
            var tuicountshow = false;
            var shouchongshow = false;
            if (Config.roleType == 'zongbu') {
                chuzhishow = true;
                tuicountshow = true;
                shouchongshow = true;
            }

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        // {field: 'type', title: __('Type'),visible:false},
                        {field: 'type', title: __('类型'), searchList: {"1":__('中心'),"2":__('空间')}, formatter: Table.api.formatter.normal},
                        // {field: 'type_text', title: '类型'},
                        {field: 'store_name', title: '名称', operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content,visible:false},
                        {field: 'store_name_cus', title: '信息', operate: false,formatter: Controller.api.formatter.store_name_cus},
                        {field: 'shouchong', title: '首笔储值剩余', operate: false,formatter: Controller.api.formatter.shouchong,visible:shouchongshow},
                        
                        {field: 'pid_text', title: '上级名称',operate: false},
                        {field: 'chuzhi_count', title: '储值总额',operate: false,visible:chuzhishow},
                        
                        // {field: 'province', title: __('Province'), operate: false},
                        // {field: 'city', title: __('City'), operate: false},
                        // {field: 'area', title: __('Area'), operate: false},
                        //{field: 'address', title: __('Address'), operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'realname', title: __('Realname'), operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'tel', title: __('Tel'), operate: 'LIKE'},
                        {field: 'tuiguang_count', title: '推广人数', operate: false,visible:tuicountshow,formatter:function (value, row, index) {
                            return '<a href="tuiguangteam/tuiguangteam?store_id='+row.id+'" class="btn-dialog" title="'+row.store_name+'-推广列表">'+value+'</a>'
                        }},
                        
                        //{field: 'contact_tel', title: __('Contact_tel'), operate: false},
                        //{field: 'bank_idcard', title: __('Bank_idcard'), operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'avatar', title: 'Logo', operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        //{field: 'idcard_z', title: __('Idcard_z'), operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'idcard_f', title: __('Idcard_f'), operate: false},
                        //{field: 'id_card_valid_start_time', title: __('Id_card_valid_start_time'), operate: 'LIKE'},
                        //{field: 'id_card_valid_time', title: __('Id_card_valid_time'), operate: 'LIKE'},
                        //{field: 'id_card_arddress', title: __('Id_card_arddress'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'email', title: __('Email'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'zizhi', title: __('Zizhi'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'zz_num', title: __('Zz_num'), operate: 'LIKE'},
                        //{field: 'merchant_name', title: __('Merchant_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'subject_type', title: __('Subject_type'), searchList: {"1":__('Subject_type 1'),"2":__('Subject_type 2')}, formatter: Table.api.formatter.normal},
                        //{field: 'license_address', title: __('License_address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'period_begin', title: __('Period_begin'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'period_end', title: __('Period_end'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'business_time', title: '营业时间', operate: false,formatter: Controller.api.formatter.business_time},

                        //{field: 'edit_time', title: __('Edit_time'), operate: 'LIKE'},
                        //{field: 'lat', title: __('Lat'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'lng', title: __('Lng'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'password', title: __('Password'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'is_ban', title: '是否解约', searchList: {"0":'正常',"1":'已解除合约'}, formatter: Table.api.formatter.normal},
                        //{field: 'is_del', title: __('Is_del'), searchList: {"0":__('Is_del 0'),"1":__('Is_del 1')}, formatter: Table.api.formatter.normal},
                        //{field: 'remark', title: __('Remark'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'authen_time', title: __('Authen_time'), operate: 'LIKE'},
                        // {field: 'bank_id', title: __('Bank_id')},
                        // {field: 'bank_province', title: __('Bank_province'), operate: 'LIKE'},
                        // {field: 'bank_area', title: __('Bank_area'), operate: 'LIKE'},
                        // {field: 'bank_no', title: __('Bank_no'), operate: 'LIKE'},
                        // {field: 'account_name', title: __('Account_name'), operate: 'LIKE'},
                        // {field: 'store_qr_code', title: __('Store_qr_code'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'applyment_id', title: __('Applyment_id'), operate: 'LIKE'},
                        // {field: 'bank_account_type', title: __('Bank_account_type'), operate: 'LIKE'},
                        // {field: 'sub_mchid', title: __('Sub_mchid'), operate: 'LIKE'},
                        // {field: 'xvstatus', title: __('Xvstatus'), searchList: {"0":__('Xvstatus 0'),"1":__('Xvstatus 1'),"2":__('Xvstatus 2'),"3":__('Xvstatus 3'),"4":__('Xvstatus 4')}, formatter: Table.api.formatter.status},
                        // {field: 'xv_reamrk', title: __('Xv_reamrk'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'start_time', title: '合同开始日期', operate:false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'end_time', title: '合同结束日期', operate:false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'add_time', title: '创建时间', operate: false, formatter: Table.api.formatter.datetime},
                        {field: 'price_low', title: '余额低于',operate: '=',visible:false},
                        //{field: 'promotion_type', title: __('Promotion_type'), searchList: {"0":__('Promotion_type 0'),"1":__('Promotion_type 1'),"2":__('Promotion_type 2'),"3":__('Promotion_type 3')}, formatter: Table.api.formatter.normal},
                        //{field: 'promotion_id', title: __('Promotion_id')},
                        //{field: 'promotion_money', title: __('Promotion_money'), operate:'BETWEEN'},
                        // {field: 'admin.username', title: __('Admin.username'), operate: 'LIKE'},
                        // {field: 'admin.nickname', title: __('Admin.nickname'), operate: 'LIKE'},
                        // {field: 'admin.mobile', title: __('Admin.mobile'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,buttons:[
                                {
                                    name: 'fenpei',
                                    title: '分配后台账号',
                                    //extend:'data-area=["860px","730px"]',
                                    text:'分配后台账号',
                                  
                                    hidden: function(row){
                                        if (row.admin.username == null) {
                                            return false;
                                        }
                                        return true;
                                    },
                                    
                                    //height:'500px',
                                    classname: 'btn btn-xs btn-info btn-primary btn-dialog',
                                    url: 'auth/admin/add?store_id={id}',
                                    callback: function (data) {
                                        //Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    }
                                },
                                {
                                    name: 'eidtaccount',
                                    title: '修改后台账号',
                                    
                                    //extend:'data-area=["860px","730px"]',
                                    text:'修改后台账号',
                                    hidden: function(row){
                                        if (row.admin.username == null) {
                                            return true;
                                        }
                                        return false;
                                    },
                                    //height:'500px',
                                    classname: 'btn btn-xs btn-success btn-primary btn-dialog',
                                    url: 'auth/admin/edit?store_id={id}',
                                    callback: function (data) {
                                        //Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    }
                                },
                                {
                                    name: 'jiechu',
                                    title: '解除合约',
                                    text: '解除合约',
                                    dropdown: "更多",
                                    hidden: function(row){
                                        if (row.is_ban == 1) {
                                            return true;
                                        }
                                        return false;
                                    },
                                    classname: 'btn btn-xs btn-danger btn-click wh',
                                    click: function (data, s) {
                                        layer.confirm('确定解除合约吗？', {
                                            btn: ['确定', '关闭'] //可以无限个按钮
                                            , btn3: function (index, layero) {
                                                //按钮【按钮三】的回调
                                            }
                                        }, function (index, layero) {
                                            //确定
                                            Fast.api.ajax({
                                                url: 'store/store/relieve',
                                                type: "post",
                                                data: {ids: s.id}
                                            }, function (data, ret) {
                                                //成功的回调
                                                //layer.alert(ret.msg);
                                                //return false;
                                                layer.close(index);
                                                table.bootstrapTable('refresh', {});
                                            }, function (data, ret) {
                                                //失败的回调
                                                //layer.alert(ret.msg);
                                                //return false;
                                                layer.close(index);
                                                table.bootstrapTable('refresh', {});
                                            });
                                        }, function (index) {
                                            //关闭
                                        });

                                    }
                                },
                                {
                                    name: 'nosale',
                                    title: '不能售卖产品',
                                    extend:'data-area=["1000px","730px"]',
                                    text:'不能售卖产品',
                                    dropdown: "更多",
                                    //height:'500px',
                                    classname: 'btn btn-xs btn-waring btn-primary btn-dialog',
                                    url: 'store/store/nosale?ids={id}',
                                    callback: function (data) {
                                        //Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    }
                                },
                                {
                                    name: 'promition_store',
                                    text: '推广记录',
                                    title: '推广记录',
                                    classname: 'btn btn-xs btn-info btn-dialog',
                                    extend: 'data-area=\'["90%", "80%"]\'',
                                    url: 'promitionlog/index?promotion_type2=-1&promotion_type=-1',
                                }
                                ,
                                {
                                    name: 'bonus_store',
                                    text: __('分红记录'),
                                    title: __('分红记录'),
                                    classname: 'btn btn-xs btn-danger btn-dialog',
                                    extend: 'data-area=\'["90%", "80%"]\'',
                                    url: 'bonusordercenter/index_store',
                                }
                                ,
                                {
                                    name: 'bonusedit_store',
                                    text: __('分红设置'),
                                    dropdown: "更多",
                                    title: __('分红设置'),
                                    classname: 'btn btn-xs btn-info btn-dialog',
                                    extend: 'data-area=\'["90%", "80%"]\'',
                                    url: 'partner/bonusedit_store',
                                }
                                ,
                                {
                                    name: 'store_goods',
                                    text: __('查看商品库存'),
                                    dropdown: "更多",
                                    title: __('查看商品库存'),
                                    classname: 'btn btn-xs btn-danger btn-dialog',
                                    extend: 'data-area=\'["90%", "80%"]\'',
                                    url: 'storegoods/index_center',
                                },
                                {
                                    name: 'sjj',
                                    title: '升级',
                                    text: '升级',
                                    dropdown: "更多",
                                    hidden: function(data){
                                        if (Config.roleType == 'zongbu') {
                                            if (data.type == 1){
                                                return true;
                                            } else {
                                                return false;
                                            }
                                        } else {
                                            return true;
                                        }
                                    },
                                    classname: 'btn btn-xs btn-success btn-click',
                                    click: function (data, s) {

                                        layer.confirm('确定将<span style="font-size: 16px;color:red;font-weight: bold;">'+s.store_name+'</span>升级为中心吗？', {
                                            btn: ['确定', '关闭'] //可以无限个按钮
                                            , btn3: function (index, layero) {
                                                //按钮【按钮三】的回调
                                            }
                                        }, function (index, layero) {
                                            $.ajax({
                                                dataType: 'json',
                                                type: 'POST',
                                                url: 'store/store/changeRole',
                                                data: {id:s.id,type:1},
                                                success: function (data) {
                                                    layer.close(index);
                                                    if (data.code == 0) {
                                                        Toastr.error(data.msg);
                                                    } else {
                                                        Toastr.success(data.msg);
                                                        setTimeout(function(){
                                                            window.location.reload();
                                                        }, 1000);
                                                    }
                                                },
                                                error: function (jqXHR, textStatus, errorThrown) {

                                                }
                                            });
                                        }, function (index) {
                                            //关闭
                                        });

                                    }
                                },
                                {
                                    name: 'jj',
                                    title: '降级',
                                    text: '降级',
                                    dropdown: "更多",
                                    hidden: function(data){
                                        if (Config.roleType == 'zongbu') {
                                            if (data.type == 1){
                                                return false;
                                            } else {
                                                return true;
                                            }
                                        } else {
                                            return true;
                                        }
                                        
                                    },
                                    classname: 'btn btn-xs btn-danger btn-click',
                                    click: function (data, s) {
                                        layer.confirm('确定将<span style="font-size: 16px;color:red;font-weight: bold;">'+s.store_name+'</span>降级为空间吗？', {
                                            btn: ['确定', '关闭'] //可以无限个按钮
                                            , btn3: function (index, layero) {
                                                //按钮【按钮三】的回调
                                            }
                                        }, function (index, layero) {
                                            $.ajax({
                                                dataType: 'json',
                                                type: 'POST',
                                                url: 'store/store/changeRole',
                                                data: {id:s.id,type:2},
                                                success: function (data) {
                                                    layer.close(index);
                                                    if (data.code == 0) {
                                                        Toastr.error(data.msg);
                                                    } else {
                                                        Toastr.success(data.msg);
                                                        setTimeout(function(){
                                                            window.location.reload();
                                                        }, 1000);
                                                    }
                                                },
                                                error: function (jqXHR, textStatus, errorThrown) {

                                                }
                                            });
                                        }, function (index) {
                                            //关闭
                                        });

                                    }
                                },
                                {
                                    name: 'zhuanyi',
                                    title: '转移下级',
                                    text: '转移下级',
                                    dropdown: "更多",
                                    hidden: function(data){
                                        if (Config.roleType == 'zongbu'){
                                            return false;
                                        } else {
                                            return true;
                                        }
                                    },
                                    classname: 'btn btn-xs btn-info btn-click',
                                    click: function (data, s) {
                                        var store_name = s.store_name;
                                        var typeid = s.type == 1 ? s.type : 0;
                                        var typename = s.type == 1 ? '中心' : '空间';
                                        var tipMsg = s.type == 1 ? '中心' : '中心/空间';
                                        // if (s.type == 1) {
                                        //     let html = Template('tpl-all-pass1', {store_name,typename});
                                        // } else {
                                        //
                                        // }
                                        let html = Template('tpl-all-pass', {store_name,typename,typeid});
                                        layer.open({
                                            type: 1,
                                            skin: 'layui-layer-demo', //样式类名
                                            title: '转移下级',
                                            anim: 2,
                                            area: ['400px', '350px'],
                                            shadeClose: 1, //开启遮罩关闭
                                            content: html,
                                            btn: ['确认', '取消'],
                                            zIndex: 10,
                                            yes: function (index) {
                                                let cid = ($('#c-c_id').val()).trim();

                                                if (!cid) {
                                                    Toastr.error('请选择'+tipMsg);
                                                    return;
                                                }

                                                $.post('store/store/changeStore', {
                                                    cid:s.id,to_cid:cid,
                                                }, function (res) {
                                                    if (res.code == 1) {
                                                        table.bootstrapTable('refresh', {pageNumber: 1});
                                                        Toastr.success(res.msg);
                                                        Layer.close(index);
                                                    } else {
                                                        Toastr.error(res.msg);
                                                    }
                                                })
                                            },
                                            success: function (layero, index) {
                                                Form.api.bindevent($('.shipper'));
                                            }
                                        });
                                    }
                                },
                                {
                                    name: 'tuiguangs',
                                    text: '佣金统计',
                                    hidden: function(data){
                                        if (Config.roleType == 'zongbu'){
                                            return false;
                                        } else {
                                            return true;
                                        }
                                    },
                                    title: function(rows){
                                        console.log(rows);
                                        return rows.store_name+'-佣金统计数据'
                                    },
                                    classname: 'btn btn-xs btn-info btn-dialog',
                                    extend: 'data-area=\'["70%", "60%"]\'',
                                    url: 'statistics/statistics/statisticscenter?store_id={id}',
                                },
                            ]}
                    ]
                ]
            });

            //操作栏编辑按钮大小
            table.on('post-body.bs.table',function(){
                $(".btn-editone").data("area",["100%","100%"]);
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        index_tj: function () {
            $(".btn-edit").data("area",["1000px","600px"]);//顶部编辑按钮

            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'store/store/index_tj' + location.search,
                    add_url: 'store/store/add',
                    edit_url: 'store/store/edit',
                    del_url: 'store/store/del',
                    multi_url: 'store/store/multi',
                    import_url: 'store/store/import',
                    table: 'store',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'type', title: __('类型'), searchList: {"1":__('中心'),"2":__('空间')}, formatter: Table.api.formatter.normal},
                        // {field: 'type_text', title: '类型'},
                        {field: 'store_name', title: '中心/空间名称', operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'province', title: __('Province'), operate: false},
                        // {field: 'city', title: __('City'), operate: false},
                        // {field: 'area', title: __('Area'), operate: false},
                        //{field: 'address', title: __('Address'), operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'realname', title: __('Realname'), operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'tel', title: __('Tel'), operate: 'LIKE'},
                        {field: 'cai_order', title: __('采购单总额'), operate:false,sortable:true},
                        {field: 'ling_order', title: __('零售总额'), operate:false,sortable:true},
                        //{field: 'contact_tel', title: __('Contact_tel'), operate: false},
                        //{field: 'bank_idcard', title: __('Bank_idcard'), operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'avatar', title: __('Avatar'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        //{field: 'idcard_z', title: __('Idcard_z'), operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'idcard_f', title: __('Idcard_f'), operate: false},
                        //{field: 'id_card_valid_start_time', title: __('Id_card_valid_start_time'), operate: 'LIKE'},
                        //{field: 'id_card_valid_time', title: __('Id_card_valid_time'), operate: 'LIKE'},
                        //{field: 'id_card_arddress', title: __('Id_card_arddress'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'email', title: __('Email'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'zizhi', title: __('Zizhi'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'zz_num', title: __('Zz_num'), operate: 'LIKE'},
                        //{field: 'merchant_name', title: __('Merchant_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'subject_type', title: __('Subject_type'), searchList: {"1":__('Subject_type 1'),"2":__('Subject_type 2')}, formatter: Table.api.formatter.normal},
                        //{field: 'license_address', title: __('License_address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'period_begin', title: __('Period_begin'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'period_end', title: __('Period_end'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'business_time', title: '营业时间', operate: false},

                        //{field: 'edit_time', title: __('Edit_time'), operate: 'LIKE'},
                        //{field: 'lat', title: __('Lat'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'lng', title: __('Lng'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'password', title: __('Password'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'is_ban', title: '是否禁用', searchList: {"0":__('Is_ban 0'),"1":__('Is_ban 1')}, formatter: Table.api.formatter.normal},
                        //{field: 'is_del', title: __('Is_del'), searchList: {"0":__('Is_del 0'),"1":__('Is_del 1')}, formatter: Table.api.formatter.normal},
                        //{field: 'remark', title: __('Remark'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'authen_time', title: __('Authen_time'), operate: 'LIKE'},
                        // {field: 'bank_id', title: __('Bank_id')},
                        // {field: 'bank_province', title: __('Bank_province'), operate: 'LIKE'},
                        // {field: 'bank_area', title: __('Bank_area'), operate: 'LIKE'},
                        // {field: 'bank_no', title: __('Bank_no'), operate: 'LIKE'},
                        // {field: 'account_name', title: __('Account_name'), operate: 'LIKE'},
                        // {field: 'store_qr_code', title: __('Store_qr_code'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'applyment_id', title: __('Applyment_id'), operate: 'LIKE'},
                        // {field: 'bank_account_type', title: __('Bank_account_type'), operate: 'LIKE'},
                        // {field: 'sub_mchid', title: __('Sub_mchid'), operate: 'LIKE'},
                        // {field: 'xvstatus', title: __('Xvstatus'), searchList: {"0":__('Xvstatus 0'),"1":__('Xvstatus 1'),"2":__('Xvstatus 2'),"3":__('Xvstatus 3'),"4":__('Xvstatus 4')}, formatter: Table.api.formatter.status},
                        // {field: 'xv_reamrk', title: __('Xv_reamrk'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'start_time', title: '合同开始日期', operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'end_time', title: '合同结束日期', operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'add_time', title: '创建时间', operate: false},
                        //{field: 'promotion_type', title: __('Promotion_type'), searchList: {"0":__('Promotion_type 0'),"1":__('Promotion_type 1'),"2":__('Promotion_type 2'),"3":__('Promotion_type 3')}, formatter: Table.api.formatter.normal},
                        //{field: 'promotion_id', title: __('Promotion_id')},
                        //{field: 'promotion_money', title: __('Promotion_money'), operate:'BETWEEN'},
                        // {field: 'admin.username', title: __('Admin.username'), operate: 'LIKE'},
                        // {field: 'admin.nickname', title: __('Admin.nickname'), operate: 'LIKE'},
                        // {field: 'admin.mobile', title: __('Admin.mobile'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,buttons:[
                                
                                {
                                    name: 'promition_store',
                                    text: __('推广空间中心记录'),
                                    title: __('推广空间中心记录'),
                                    classname: 'btn btn-xs btn-info btn-dialog',
                                    extend: 'data-area=\'["90%", "80%"]\'',
                                    url: 'promitionlog/index?promotion_type2=-1&promotion_type=-1',
                                }
                                ,
                                {
                                    name: 'bonus_store',
                                    text: __('分红记录'),
                                    title: __('分红记录'),
                                    classname: 'btn btn-xs btn-danger btn-dialog',
                                    extend: 'data-area=\'["90%", "80%"]\'',
                                    url: 'bonusordercenter/index_store',
                                }
                                
                                
                            ]}
                    ]
                ],
                searchFormTemplate: 'customformtpl',
            });

            //操作栏编辑按钮大小
            table.on('post-body.bs.table',function(){
                $(".btn-editone").data("area",["100%","100%"]);
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            //选择空间中心
            $(document).on('change', '#c-type', function () {
                if ($(this).val() == 1) {
                    //中心
                    $(".c-area_ids").show();
                    $('form[role=form]').data('validator').options.ignore = '';
                    $(".c-store_id").remove();
                    $("#area_tip").hide();
                } else {
                    //空间
                    $(".c-area_ids").hide();
                    $('form[role=form]').data('validator').options.ignore = '#c-area_ids';
                    
                    var region_area = $("#c-area").val();
                    if (!region_area) {
                        return false;
                    }

                    $.ajax({
                        dataType: 'json',
                        type: 'POST',
                        url: 'ajax/checkCenter',
                        data: {area:$(this).val()},
                        success: function (data) {
                            if (data.code == 201) {
                                $(".c-store_id").remove();
                                //动态追加选择中心select
                                $(".one_sel").after('<div class="form-group c-store_id">\n' +
                                    '        <label class="control-label col-xs-12 col-sm-2">指派空间所属中心:</label>\n' +
                                    '        <div class="col-xs-12 col-sm-8">\n' +
                                    '            <input id="c-pid" data-rule="required" data-source="ajax/getAllstore?type=1"\n' +
                                    '                   class="form-control selectpage"\n' +
                                    '                   name="row[pid]"\n' +
                                    '                   type="text" value="">\n' +
                                    '        </div>\n' +
                                    '    </div>');

                                $("#area_tip").show();
                                $('form[role=form]').data('validator').options.ignore = '';
                                $('form[role=form]').data('validator').options.ignore = '#c-area_ids';
                                Form.events.selectpage($("#add-form"));
                            } else {
                                $(".c-store_id").remove();
                                $("#area_tip").hide();
                            }
                        },
                        error: function (jqXHR, textStatus, errorThrown) {

                        }
                    });
                }
            });

            $(document).on('change', '#c-area', function () {
                var type = $("#c-type").val();
                //空间判断所属中心
                if (type == 2) {
                    $.ajax({
                        dataType: 'json',
                        type: 'POST',
                        url: 'ajax/checkCenter',
                        data: {area:$(this).val()},
                        success: function (data) {
                            if (data.code == 201) {
                                $(".c-store_id").remove();
                                //动态追加选择中心select
                                $(".one_sel").after('<div class="form-group c-store_id">\n' +
                                    '        <label class="control-label col-xs-12 col-sm-2">指派空间所属中心:</label>\n' +
                                    '        <div class="col-xs-12 col-sm-8">\n' +
                                    '            <input id="c-pid" data-rule="required" data-source="ajax/getAllstore?type=1"\n' +
                                    '                   class="form-control selectpage"\n' +
                                    '                   name="row[pid]"\n' +
                                    '                   type="text" value="">\n' +
                                    '        </div>\n' +
                                    '    </div>');

                                $("#area_tip").show();
                                $('form[role=form]').data('validator').options.ignore = '';
                                $('form[role=form]').data('validator').options.ignore = '#c-area_ids';
                                Form.events.selectpage($("#add-form"));
                            } else {
                                $(".c-store_id").remove();
                                $("#area_tip").hide();
                            }
                        },
                        error: function (jqXHR, textStatus, errorThrown) {

                        }
                    });
                }

            });

            $(document).on('change', '#c-pid', function () {
                if ($(this).val()) {
                    $("#area_tip").hide();
                } else {
                    $("#area_tip").show();
                }
            });

            //不验证不可见表单
            $('form[role=form]').data("validator-options", {
                ignore: ':hidden'
            });
            Controller.api.bindevent();
        },
        edit: function () {
            $(document).on('change', '#c-area', function () {
                var type = $("#c-type").val();
                //空间判断所属中心  && !Config.pid
                if (type == 2) {
                    $.ajax({
                        dataType: 'json',
                        type: 'POST',
                        url: 'ajax/checkCenter',
                        data: {area:$(this).val()},
                        success: function (data) {
                            if (data.code == 201) {
                                $(".c-store_id").remove();
                                //动态追加选择中心select
                                $(".one_sel").after('<div class="form-group c-store_id">\n' +
                                    '        <label class="control-label col-xs-12 col-sm-2">指派空间所属中心:</label>\n' +
                                    '        <div class="col-xs-12 col-sm-8">\n' +
                                    '            <input id="c-pid" data-rule="required" data-source="ajax/getAllstore?type=1"\n' +
                                    '                   class="form-control selectpage"\n' +
                                    '                   name="row[pid]"\n' +
                                    '                   type="text" value="">\n' +
                                    '        </div>\n' +
                                    '    </div>');

                                $("#area_tip").show();
                                $('form[role=form]').data('validator').options.ignore = '';
                                Form.events.selectpage($("#edit-form"));
                            } else {
                                $(".c-store_id").remove();
                                $("#area_tip").hide();
                            }
                        },
                        error: function (jqXHR, textStatus, errorThrown) {

                        }
                    });
                }

            });

            $(document).on('change', '#c-pid', function () {
                if ($(this).val()) {
                    $("#area_tip").hide();
                } else {
                    $("#area_tip").show();
                }
            });

            //不验证不可见表单
            $('form[role=form]').data("validator-options", {
                ignore: ':hidden'
            });
            Controller.api.bindevent();
        },
        edit_self: function () {
            Controller.api.bindevent();

            //初始赋值
            setTimeout(function(){
                //赋值钱，必须先执行reset、destory
                $("#c-pca").citypicker('reset');
                $("#c-pca").citypicker('destroy');
                $("#c-pca").citypicker({
                    province: Config.storeCpa.province,
                    city: Config.storeCpa.city,
                    district: Config.storeCpa.area
                });

                $("#c-bank_pc").citypicker('reset');
                $("#c-bank_pc").citypicker('destroy');
                $("#c-bank_pc").citypicker({
                    province: Config.storeCp.province,
                    city: Config.storeCp.city
                });


            }, 800);






        },
        edit_zfb: function () {
            Controller.api.bindevent();
        },
        adminadd: function () {
            Controller.api.bindevent();
            Form.api.bindevent($("form[role=form]"));
        },
        adminedit: function () {
            Controller.api.bindevent();
            Form.api.bindevent($("form[role=form]"));
        },
        firstprice: function () {
            Controller.api.bindevent();
        },
        statistics: function () {
            Controller.api.bindevent();
        },
        nosale: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'store/store/nosale' + location.search,
                    table: 'goods',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                commonSearch: false,
                visible: false,
                showToggle: false,
                showColumns: false,
                search:false,
                showExport: false,
                columns: [
                    [
                        {field: 'id', title: '产品ID'},
                        {field: 'goods_name', title: '产品名称', operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'image', title: '图片', operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        //{field: 'spec_name', title: __('Spec_name'), operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'cost_price', title: '成本价', operate: false},
                        {field: 'price', title: '零售价', operate: false},
                        {field: 'line_price', title: '划线价', operate: false},
                        {field: 'cashsale', title: '虚拟销量', operate: false},
                        {field: 'salecount', title: '真实销量', operate: false},
                        {field: 'pv', title: 'pv', operate: false},
                        {field: 'addtime', title: '创建时间', operate: false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,buttons:[
                                {
                                    name: 'yichu',
                                    title: '移除',
                                    classname: 'btn btn-xs btn-danger btn-click',
                                    text: '移除',
                                    //dropdown: '更多',//如果包含dropdown，将会以下拉列表的形式展示
                                    click: function (data, s) {
                                        Fast.api.ajax({
                                            url:'store/store/nosaleDelete',
                                            data:{id:s.id,store_id:Config.store_id}
                                        }, function(data, ret){
                                            //成功的回调
                                            table.bootstrapTable('refresh', {});
                                        }, function(data, ret){
                                            //失败的回调
                                            table.bootstrapTable('refresh', {});
                                        });
                                    }
                                }
                            ]}
                    ]
                ]
            });


            //提交中心/空间不能售卖商品
            $(document).on('click', '.btn-tjnosend', function () {
                var value = $("#c-goods_name").val();
                if (!value) {
                    Toastr.error('请选不能售卖商品');
                    return false;
                }

                Fast.api.ajax({
                    url:'store/store/nosaleSubmit',
                    data:{ids:value,store_id:Config.store_id}
                }, function(data, ret){
                    //成功的回调
                    //$("#c-goods_name").val('');
                    //table.bootstrapTable('refresh', {});
                    setTimeout(function () {
                        window.location.reload();
                    }, 500);

                }, function(data, ret){
                    //失败的回调
                    setTimeout(function () {
                        window.location.reload();
                    }, 500);
                });
            });

            Form.events.selectpage($("#toolbar"));

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));

            },
            formatter: {//渲染的方法
                business_time: function (value, row, index) {
                    var btime = "-";
                    var etime = "-";
                    if (!row.business_start_time && !row.business_end_time) {
                        return "-";
                    }
                    if (row.business_start_time) {
                        btime = row.business_start_time;
                    }
                    if (row.business_end_time) {
                        etime = row.business_end_time;
                    }
                    return btime+"至"+etime;
                },
                store_name_cus: function (value, row, index) {
                    if (Config.roleType == 'zongbu') {
                        return '<div class="c_n_1">'+row.store_name+'</div><div>储值余额：<span class="c_1">'+row.storage_balance+'</span>&nbsp;&nbsp;  利润余额：<span class="c_2">'+row.balance+'</span></div>';
                    }
                },
                shouchong: function (value, row, index) {
                    if (Config.roleType == 'zongbu') {
                        return row.first_storage_balance;
                    }
                },
            }
        }
    };
    return Controller;
});
